import { IObject } from "@/types/interface";

/**
 * 是否只null和undefined值
 * @param vl
 * @returns
 */
export const isNullOrUndefined = (vl: unknown): boolean => {
  return vl === null || typeof vl === "undefined";
};

  /**
 * 获取uuid
 */
export const getUuid = (): string => {
  return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
    const r = (Math.random() * 16) | 0,
      v = c == "x" ? r : (r & 0x3) | 0x8;
    return v.toString(16);
  });
};

export const getValueByKeys = (record: IObject = {}, key: string, defaultValue?: unknown): any=>{
  const keys = key.split(".");
  for ( let i = 0; i < keys.length; i++) {
    record = record[keys[i]] || (i === keys.length -1 ? defaultValue : {});
  }
  return record || defaultValue;
}
/**
 * 检查是否有权限
 */
export const checkPermission = (permission: string[], key: string): boolean => {
  return permission.includes(key);
}